<%@ page import="weaver.conn.RecordSet" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.hrm.OnLineMonitor" %>
<%@ page import="weaver.hrm.User" %>
<%@ page import="weaver.systeminfo.template.UserTemplate" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%
    BaseBean baseBean = new BaseBean();
    baseBean.writeLog("in---KeyLoginAction");
    String tourl = "/wui/main.jsp";
    try {
        String workcode = Util.null2String(request.getParameter("workcode"));
        String cookiename = "";
        String cookievalue = "";
        Cookie[] cookies = request.getCookies();
        if (cookies != null && cookies.length > 0) {
            for (Cookie cookie : cookies) {
                cookiename = cookie.getName();
                cookievalue = new String(URLDecoder.decode(cookie.getValue()).getBytes("ISO-8859-1"), "GBK");
                if ("KOAL_CERT_E".equals(cookiename)) {
                    workcode = cookievalue.substring(0, cookievalue.indexOf("@"));
                }
            }
        }
        baseBean.writeLog("用户标识：" + workcode);
        RecordSet rs = new RecordSet();
        rs.execute("select * from hrmresource where workcode='" + workcode + "' and status<='3'");
        User user = null;
        if (rs.next()) {
            user = new User();
            user.setUid(rs.getInt("id"));
            user.setLoginid(rs.getString("loginid"));
            user.setFirstname(rs.getString("firstname"));
            user.setLastname(rs.getString("lastname"));
            user.setAliasname(rs.getString("aliasname"));
            user.setTitle(rs.getString("title"));
            user.setTitlelocation(rs.getString("titlelocation"));
            user.setSex(rs.getString("sex"));
            user.setPwd(rs.getString("password"));
            String languageidweaver = rs.getString("systemlanguage");
            user.setLanguage(Util.getIntValue(languageidweaver, 0));

            user.setTelephone(rs.getString("telephone"));
            user.setMobile(rs.getString("mobile"));
            user.setMobilecall(rs.getString("mobilecall"));
            user.setEmail(rs.getString("email"));
            user.setCountryid(rs.getString("countryid"));
            user.setLocationid(rs.getString("locationid"));
            user.setResourcetype(rs.getString("resourcetype"));
            user.setStartdate(rs.getString("startdate"));
            user.setEnddate(rs.getString("enddate"));
            user.setContractdate(rs.getString("contractdate"));
            user.setJobtitle(rs.getString("jobtitle"));
            user.setJobgroup(rs.getString("jobgroup"));
            user.setJobactivity(rs.getString("jobactivity"));
            user.setJoblevel(rs.getString("joblevel"));
            user.setSeclevel(rs.getString("seclevel"));
            user.setUserDepartment(Util.getIntValue(rs.getString("departmentid"), 0));
            user.setUserSubCompany1(Util.getIntValue(rs.getString("subcompanyid1"), 0));
            user.setUserSubCompany2(Util.getIntValue(rs.getString("subcompanyid2"), 0));
            user.setUserSubCompany3(Util.getIntValue(rs.getString("subcompanyid3"), 0));
            user.setUserSubCompany4(Util.getIntValue(rs.getString("subcompanyid4"), 0));
            user.setManagerid(rs.getString("managerid"));
            user.setAssistantid(rs.getString("assistantid"));
            user.setPurchaselimit(rs.getString("purchaselimit"));
            user.setCurrencyid(rs.getString("currencyid"));
            user.setLastlogindate(rs.getString("currentdate"));
            user.setLogintype("1");
            user.setAccount(rs.getString("account"));
            user.setLoginip(request.getRemoteAddr());
            request.getSession(true).setMaxInactiveInterval(60 * 60 * 24);
            request.getSession(true).setAttribute("weaver_user@bean", user);
            request.getSession(true).setAttribute("moniter", new OnLineMonitor("" + user.getUID(), user.getLoginip()));
            Util.setCookie(response, "loginfileweaver", "/main.jsp", 172800);
            Util.setCookie(response, "loginidweaver", "" + user.getUID(), 172800);
            Util.setCookie(response, "languageidweaver", languageidweaver, 172800);
            //用户的登录后的页面
            UserTemplate ut = new UserTemplate();
            ut.getTemplateByUID( user.getUID(), user.getUserSubCompany1() );
            String defaultHp = ut.getDefaultHp();
            session.setAttribute( "defaultHp", defaultHp );
            Map logmessages = (Map) application.getAttribute( "logmessages" );
            if (logmessages == null) {
                logmessages = new HashMap();
                logmessages.put( "" + user.getUID(), "" );
                application.setAttribute( "logmessages", logmessages );
            }
            session.setAttribute( "logmessage", "" );
            response.sendRedirect( tourl );
        }
    } catch (Exception e) {
        response.sendRedirect( tourl );
    }
%>

